<?php
/**
 * @autor Alex Yépez <ayepez@tradesystem.com.ec>
 * carga de usuerios oportunidad y supervisor de la campaña
 */
$usersCampania = new CampaniaUsuarioCruge;
$userDataProvider = $usersCampania->searchTipoRolCampania($model->id, Constants::ROL_SUPERVISOR);
?>
<div class="widget yellow">
    <div class="widget-title">
        <h4><i class="icon-user"></i> Supervisor</h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <!--a href="javascript:;" class="icon-remove"></a-->
        </span>
    </div>
    <div class="widget-body">
        <?php if ($userDataProvider->getData()): ?>
            <div style='overflow:auto'> 
                <?php
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id' => 'addSupervisor-grid',
                    'afterAjaxUpdate' => "function(id,data){AjaxActualizarActividades();}",
                    'type' => 'striped bordered hover advance',
                    'dataProvider' => $userDataProvider,
                    //'selectableRows' => 2,
                    'columns' => array(
                        array(
                            'name' => 'Nombre',
                            'value' => 'Yii::app()->user->um->loadUserById($data->usuario_id)->username',
                            'type' => 'raw',
                        ),
                        array(
                            'name' => 'Ultima Session',
                            'type' => 'raw',
                            'value' => '$data->ultimaSesionUsuario("$data->usuario_id")',
                        ),
                   
                        array(
                            'class' => 'CButtonColumn',
                            'template' => '{delete}',
                            'buttons' => array(
                                'delete' => array(
                                    'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                    'options' => array('title' => 'Eliminar'),
                                    'url' => 'Yii::app()->createUrl("campanias/campaniaUsuarioCruge/delete", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_campaniaUsuarioCruge_delete"))',
                                ),
                            ),
                            'htmlOptions' => array(
                                'width' => '40px'
                            )
                        ),
                    ),
                ));
                ?>
            </div>
            <br>

        <?php endif; ?>

        <?php
        Util::checkAccess(array("action_cobranza_create")) ?
                        $this->widget(
                                'bootstrap.widgets.TbButton', array(
                            'id' => 'add-usuarios',
                            'label' => ($userDataProvider->getData() ? '' : '<br>') . 'Agregar Supervisor',
                            'encodeLabel' => false,
                            'icon' => $userDataProvider->getData() ? 'plus-sign' : 'icon-user',
                            'htmlOptions' => array(
                                'onClick' => 'js:viewModal("campanias/campaniaUsuarioCruge/create/campania_id/' . $model->id . '/tipoRol/' . Constants::ROL_SUPERVISOR . '",function(){'
                                . 'maskAttributes();})',
                                'class' => $userDataProvider->getData() ? '' : 'empty-portlet',
                            ),
                                )
                        ) : '';
        ?>

    </div>
</div>
